package com.mall.config;


import com.mall.common.Constant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @Package: com.mall.config
 * @author: cxx
 * @Create: 2023/4/21-10:48
 * @Description: 配置RabbitMQ队列 交换机 路由表key绑定关系
 */
@Configuration
public class RabbitMqConfig {
    @Bean
    public CustomExchange orderExchange() {
        Map<String, Object> args = new HashMap<>(16);
        args.put("x-delayed-type", "direct");
        return new CustomExchange(Constant.ORDEREXCHANGE, "x-delayed-message",
                true, false, args);
    }

    @Bean
    public Queue orderQueue() {
        return new Queue(Constant.ORDERQUEUE, true, false, false);
    }

    @Bean
    public Binding directBind() {
        return BindingBuilder.bind(orderQueue()).to(orderExchange()).with(Constant.ORDERKEY).noargs();
    }


}
